package my.assistant.util;

import my.assistant.reminder.RemindVO;


public final class ArrayUtils
{
	public static void setBoolVal(boolean[] arr, int start, int end, boolean val)
	{
		if (start > end)
			throw new IllegalArgumentException("start must small than end.");
		for (int i = 0; i < arr.length; i++)
        {
			if (i >= start && i <= end)
				arr[i] = val;
			else
				arr[i] = val == false;
        }
	}

	public static void buildWeek(StringBuilder buff, boolean[] arr, String[] sArr, String s)
	{
		buff.setLength(0);
		buff.append(s);
		buff.append(Constants.BLANK);
		boolean has = false;
		for (int i = 0; i < arr.length; i++)
		{
			if (arr[i])
			{
				if (i != 0 && has)
				{
					buff.append(Constants.COMA);
				}
				has = true;
				buff.append(sArr[i]);
			}
		}
	}

	public static void buildTime(StringBuilder buff, RemindVO remindVO, String s)
	{
		buff.setLength(0);
        buff.append(s);
        buff.append(Constants.BLANK);
        buff.append(remindVO.hour > 9 ? remindVO.hour : Constants.ZERO + remindVO.hour);
        buff.append(Constants.COLON);
        buff.append(remindVO.minute > 9 ? remindVO.minute : Constants.ZERO + remindVO.minute);
	}

	public static void buildSound(StringBuilder buff, RemindVO remindVO, String s)
	{
		buff.setLength(0);
		buff.append(s);
		buff.append(Constants.BLANK);
		buff.append(remindVO.sound);
	}

	public static String toString(boolean[] obj)
    {
		final StringBuilder buff = new StringBuilder();
		boolean first = true;
		for (boolean b : obj)
        {
			if (first == false)
			{
				buff.append(Constants.COMA);
			}
			first = false;
	        buff.append(b);
        }
	    return buff.toString();
    }
}
